package com.jt.consumer.service;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Feign回调工厂对象,基于此对象创建Fegin接口实现类对象
 * 这个实现类对象,用于做容错处理(有备无患,这里做熔断处理)
 */
@Component

public class ProviderFallbackFactory implements FallbackFactory<RemoteProviderService> {
//    @Override
//    public RemoteProviderService create(Throwable throwable) {
//        return new RemoteProviderService() {
//            @Override
//            public String echoMessage(String string) {
//                return "服务暂时不可用,稍等片刻在访问";
//            }
//        };

    private static final Logger log = LoggerFactory.getLogger(ProviderFallbackFactory.class);
@Override
public RemoteProviderService create(Throwable throwable) {
    return msg ->{
        log.error("error:{}","服务调用失败");
        return "服务暂时不可用,稍等片刻在访问";
    };
    }

}
